package com.marketingManagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eight.pojo.TbCustomerIssues;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.marketingManagement.dao.customerIssuesMapper;
import com.marketingManagement.service.customerIssuesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author caoch
 * @since 2023/2/28 16:36
 **/
@Service
public class customerIssuesServiceImpl extends ServiceImpl<customerIssuesMapper, TbCustomerIssues> implements customerIssuesService {
	@Autowired
	private customerIssuesMapper customerIssuesMapper;

	/**
	 * 添加问答
	 * @param customerIssues
	 * @return
	 */
	public int addCustomerIssues(TbCustomerIssues customerIssues) {
		return customerIssuesMapper.insert(customerIssues);
	}

	/**
	 * 修改问答
	 * @param customerIssues
	 * @return
	 */
	public int updateCustomerIssues(TbCustomerIssues customerIssues){
		QueryWrapper<TbCustomerIssues> wrapper = new QueryWrapper<>();
		wrapper.eq("id",customerIssues.getId());
		return customerIssuesMapper.update(customerIssues,wrapper);
	}

	/**
	 * 删除问答
	 * @param id
	 * @return
	 */
	public int removeCustomerIssues(int id){
		return customerIssuesMapper.deleteById(id);
	}

	/**
	 * 模糊查询问答
	 * @param currentPage
	 * @param pageSize
	 * @param customerIssues
	 * @return list
	 */
	public PageInfo<TbCustomerIssues> selectCustomerIssues(Integer currentPage, Integer pageSize, TbCustomerIssues customerIssues){
		PageHelper.startPage(currentPage,pageSize);
		QueryWrapper<TbCustomerIssues> wrapper = new QueryWrapper<>();
		wrapper.like(customerIssues.getSubmodule()!=null,"submodule",customerIssues.getSubmodule());
		List<TbCustomerIssues> tbCustomerIssues = customerIssuesMapper.selectList(wrapper);
		PageInfo<TbCustomerIssues> tbCustomerIssuesPageInfo = new PageInfo<>(tbCustomerIssues);
		return tbCustomerIssuesPageInfo;
	}

	/**
	 * 查询对应模块的信息
	 * @param submodule
	 * @return
	 */
	public List<TbCustomerIssues> selectIssues(String submodule){
		QueryWrapper<TbCustomerIssues> wrapper = new QueryWrapper<>();
		wrapper.eq(submodule!=null,"submodule",submodule);
		List<TbCustomerIssues> tbCustomerIssues = customerIssuesMapper.selectList(wrapper);
		return tbCustomerIssues;
	}

}
